package com.sphd.emanu.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.emanu.R;
import com.sphd.emanu.pojo.order.Order;
import com.wzutils.BigDisMailUtils;
import com.wzutils.TimeUtils;

import java.util.List;

/**
 * @Author Hu
 * @Time 2017/7/4 --17:28.
 * @Email 87683202@qq.com
 */
public class GoodOrderDetailAdapter extends BaseQuickAdapter<Order, BaseViewHolder> {
    Context context;
    int flag;

    public GoodOrderDetailAdapter(@LayoutRes int layoutResId, @Nullable List<Order> data, Context context, int flag) {
        super(layoutResId, data);
        this.context = context;
        this.flag = flag;
    }

    @Override
    protected void convert(BaseViewHolder helper, Order item) {
        /**
         status订单状态,0-订单取消,1-订单提交,2-订单接受,3-订单拒绝,4-订单派送,5-订单完成,9-过期订单
         原型上的状态顺序为12450
         原型上的取消按钮变为拒绝,
         修改订单状态时,要变成啥状态就传对应的状态值,比如,要接受,就传2,要取消,就传0
         */
        helper
                .addOnClickListener(R.id.item_btn_rec)
                .addOnClickListener(R.id.item_btn_cancle)
                .addOnClickListener(R.id.item_send)
                .addOnClickListener(R.id.item_pay_bill)
                .addOnClickListener(R.id.item_print_p)
                .setText(R.id.item_order_time,"下单时间"+ TimeUtils.dateToString(item.getCreateDate(), TimeUtils.YEAR_MONTH_DAY_HOUR_MIN))
                .setText(R.id.item_card_pay,"充值卡支付￥"+ item.getDeposit())
                .setVisible(R.id.item_btn_rec, flag == 0 ? true : false)
                .setVisible(R.id.item_btn_cancle, flag == 0 ? true : false)
                .setVisible(R.id.item_send, flag == 1 ? true : false)
                .setVisible(R.id.item_pay_bill, flag == 2 ? true : false)
                .setVisible(R.id.item_print_p, flag == 3 ? true : false)
                .setText(R.id.item_order_type, item.getType().equals("1") ? "店内" : "外卖")
                .setTextColor(R.id.item_order_type, item.getType().equals("1") ? ContextCompat.getColor(context, R.color.blue) : ContextCompat.getColor(context, R.color.white))
                .setBackgroundColor(R.id.item_order_type, item.getType().equals("1") ? ContextCompat.getColor(context, R.color.white) : ContextCompat.getColor(context, R.color.blue))
                .setText(R.id.item_money_pay, "现金支付￥"+BigDisMailUtils.turnTrim(item.getAmountPaid(), 2));

    }
}
